home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / gcc263-src.lha / gcc-2.6.3 / cp / error.c < prev    next >
C/C++ Source or Header  |  1994-09-26  |  32KB  |  1,440 lines

  1. /* Call-backs for C++ error reporting.
  2.    This code is non-reentrant.
  3.    Copyright (C) 1993 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "config.h"
  22. #include "tree.h"
  23. #include "cp-tree.h"
  24. #include "obstack.h"
  25. #include <ctype.h>
  26.  
  27. typedef char* cp_printer ();
  28.  
  29. #define A args_as_string
  30. #define C code_as_string
  31. #define D decl_as_string
  32. #define E expr_as_string
  33. #define L language_as_string
  34. #define O op_as_string
  35. #define P parm_as_string
  36. #define T type_as_string
  37.  
  38. #define _ (cp_printer *) 0
  39. cp_printer * cp_printers[256] =
  40. /*0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F */
  41.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x00 */
  42.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x10 */
  43.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x20 */
  44.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x30 */
  45.   _, A, _, C, D, E, _, _, _, _, _, _, L, _, _, O, /* 0x40 */
  46.   P, _, _, _, T, _, _, _, _, _, _, _, _, _, _, _, /* 0x50 */
  47.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x60 */
  48.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x70 */
  49. };
  50. #undef C
  51. #undef D
  52. #undef E
  53. #undef L
  54. #undef O
  55. #undef P
  56. #undef T
  57. #undef _
  58.  
  59. #define obstack_chunk_alloc xmalloc
  60. #define obstack_chunk_free free
  61.  
  62. /* Obstack where we build text strings for overloading, etc.  */
  63. static struct obstack scratch_obstack;
  64. static char *scratch_firstobj;
  65.  
  66. # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
  67. # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
  68. # define OB_PUTC2(C1,C2)    \
  69.   (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
  70. # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
  71. # define OB_PUTID(ID)  \
  72.   (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID),    \
  73.          IDENTIFIER_LENGTH (ID)))
  74. # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
  75. # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
  76. # define OB_PUTI(CST) do { sprintf (digit_buffer, "%d", (CST)); \
  77.                OB_PUTCP (digit_buffer); } while (0)
  78. # define OB_UNPUT(N) obstack_blank (&scratch_obstack, - (N));
  79.  
  80. # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
  81.  
  82. static void dump_type (), dump_decl (), dump_function_decl ();
  83. static void dump_expr (), dump_unary_op (), dump_binary_op ();
  84. static void dump_aggr_type (), dump_type_prefix (), dump_type_suffix ();
  85. static void dump_function_name ();
  86.  
  87. void
  88. init_error ()
  89. {
  90.   gcc_obstack_init (&scratch_obstack);
  91.   scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
  92. }
  93.  
  94. enum pad { none, before, after };
  95.  
  96. static void
  97. dump_readonly_or_volatile (t, p)
  98.      tree t;
  99.      enum pad p;
  100. {
  101.   if (TYPE_READONLY (t) || TYPE_VOLATILE (t))
  102.     {
  103.       if (p == before) OB_PUTC (' ');
  104.       if (TYPE_READONLY (t))
  105.     OB_PUTS ("const");
  106.       if (TYPE_READONLY (t) && TYPE_VOLATILE (t))
  107.     OB_PUTC (' ');
  108.       if (TYPE_VOLATILE (t))
  109.     OB_PUTS ("volatile");
  110.       if (p == after) OB_PUTC (' ');
  111.     }
  112. }
  113.  
  114. /* This must be large enough to hold any printed integer or floating-point
  115.    value.  */
  116. static char digit_buffer[128];
  117.  
  118. /* Dump into the obstack a human-readable equivalent of TYPE. */
  119. static void
  120. dump_type (t, v)
  121.      tree t;
  122.      int v;            /* verbose? */
  123. {
  124.   if (t == NULL_TREE)
  125.     return;
  126.   
  127.   if (TYPE_PTRMEMFUNC_P (t))
  128.     goto offset_type;
  129.  
  130.   switch (TREE_CODE (t))
  131.     {
  132.     case ERROR_MARK:
  133.       OB_PUTS ("{error}");
  134.       break;
  135.  
  136.     case UNKNOWN_TYPE:
  137.       OB_PUTS ("{unknown type}");
  138.       break;
  139.  
  140.     case TREE_LIST:
  141.       /* i.e. function taking no arguments */
  142.       if (t != void_list_node)
  143.     {
  144.       dump_type (TREE_VALUE (t), v);
  145.       /* Can this happen other than for default arguments? */
  146.       if (TREE_PURPOSE (t) && v)
  147.         {
  148.           OB_PUTS (" = ");
  149.           dump_expr (TREE_PURPOSE (t));
  150.         }
  151.       if (TREE_CHAIN (t))
  152.         {
  153.           if (TREE_CHAIN (t) != void_list_node)
  154.         {
  155.           OB_PUTC2 (',', ' ');
  156.           dump_type (TREE_CHAIN (t), v);
  157.         }
  158.         }
  159.       else OB_PUTS (" ...");
  160.     }
  161.       break;
  162.  
  163.     case IDENTIFIER_NODE:
  164.       OB_PUTID (t);
  165.       break;
  166.  
  167.     case TREE_VEC:
  168.       dump_type (BINFO_TYPE (t), v);
  169.       break;
  170.  
  171.     case RECORD_TYPE:
  172.     case UNION_TYPE:
  173.     case ENUMERAL_TYPE:
  174.       if (TYPE_LANG_SPECIFIC (t)
  175.       && (IS_SIGNATURE_POINTER (t) || IS_SIGNATURE_REFERENCE (t)))
  176.     {
  177.       if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
  178.         dump_readonly_or_volatile (t);
  179.       dump_type (SIGNATURE_TYPE (t), v);
  180.       if (IS_SIGNATURE_POINTER (t))
  181.         OB_PUTC ('*');
  182.       else
  183.         OB_PUTC ('&');
  184.     }
  185.       else
  186.     dump_aggr_type (t, v);
  187.       break;
  188.  
  189.     case TYPE_DECL:
  190.       dump_decl (t, v);
  191.       break;
  192.  
  193.     case INTEGER_TYPE:
  194.       if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
  195.     OB_PUTS ("unsigned ");
  196.       else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
  197.     OB_PUTS ("signed ");
  198.  
  199.       /* fall through.  */
  200.     case REAL_TYPE:
  201.     case VOID_TYPE:
  202.     case BOOLEAN_TYPE:
  203.       dump_readonly_or_volatile (t, after);
  204.       OB_PUTID (TYPE_IDENTIFIER (t));
  205.       break;
  206.  
  207.     case TEMPLATE_TYPE_PARM:
  208.       OB_PUTID (TYPE_IDENTIFIER (t));
  209.       break;
  210.  
  211.     case UNINSTANTIATED_P_TYPE:
  212.       OB_PUTID (DECL_NAME (UPT_TEMPLATE (t)));
  213.       OB_PUTS ("<...>");
  214.       break;
  215.  
  216.       /* This is not always necessary for pointers and such, but doing this
  217.      reduces code size.  */
  218.     case ARRAY_TYPE:
  219.     case POINTER_TYPE:
  220.     case REFERENCE_TYPE:
  221.     case OFFSET_TYPE:
  222.     offset_type:
  223.     case FUNCTION_TYPE:
  224.     case METHOD_TYPE:
  225.       dump_type_prefix (t, v);
  226.       dump_type_suffix (t, v);
  227.       break;
  228.  
  229.     default:
  230.       sorry ("`%s' not supported by dump_type",
  231.          tree_code_name[(int) TREE_CODE (t)]);
  232.     }
  233. }
  234.  
  235. static char *
  236. aggr_variety (t)
  237.      tree t;
  238. {
  239.   if (TREE_CODE (t) == ENUMERAL_TYPE)
  240.     return "enum";
  241.   else if (TREE_CODE (t) == UNION_TYPE)
  242.     return "union";
  243.   else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
  244.     return "class";
  245.   else if (TYPE_LANG_SPECIFIC (t) && IS_SIGNATURE (t))
  246.     return "signature";
  247.   else
  248.     return "struct";
  249. }
  250.  
  251. /* Print out a class declaration, in the form `class foo'. */
  252. static void
  253. dump_aggr_type (t, v)
  254.      tree t;
  255.      int v;            /* verbose? */
  256. {
  257.   tree name;
  258.   char *variety = aggr_variety (t);
  259.  
  260.   dump_readonly_or_volatile (t, after);
  261.  
  262.   if (v > 0)
  263.     {
  264.       OB_PUTCP (variety);
  265.       OB_PUTC (' ');
  266.     }
  267.   
  268.   name = TYPE_NAME (t);
  269.  
  270.   if (DECL_CONTEXT (name))
  271.     {
  272.       /* FUNCTION_DECL or RECORD_TYPE */
  273.       dump_decl (DECL_CONTEXT (name), 0);
  274.       OB_PUTC2 (':', ':');
  275.     }
  276.  
  277.   /* kludge around wierd behavior on g++.brendan/line1.C */
  278.   if (TREE_CODE (name) != IDENTIFIER_NODE)
  279.     name = DECL_NAME (name);
  280.  
  281.   if (ANON_AGGRNAME_P (name))
  282.     {
  283.       OB_PUTS ("{anonymous");
  284.       if (!v)
  285.     {
  286.       OB_PUTC (' ');
  287.       OB_PUTCP (variety);
  288.     }
  289.       OB_PUTC ('}');
  290.     }
  291.   else
  292.     OB_PUTID (name);
  293. }
  294.  
  295. /* Dump into the obstack the initial part of the output for a given type.
  296.    This is necessary when dealing with things like functions returning
  297.    functions.  Examples:
  298.  
  299.    return type of `int (* fee ())()': pointer -> function -> int.  Both
  300.    pointer (and reference and offset) and function (and member) types must
  301.    deal with prefix and suffix.
  302.  
  303.    Arrays must also do this for DECL nodes, like int a[], and for things like
  304.    int *[]&.  */
  305.  
  306. static void
  307. dump_type_prefix (t, v)
  308.      tree t;
  309.      int v;            /* verbosity */
  310. {
  311.   if (TYPE_PTRMEMFUNC_P (t))
  312.     {
  313.       t = TYPE_PTRMEMFUNC_FN_TYPE (t);
  314.       goto offset_type;
  315.     }
  316.   
  317.   switch (TREE_CODE (t))
  318.     {
  319.     case POINTER_TYPE:
  320.       {
  321.     tree sub = TREE_TYPE (t);
  322.     
  323.     dump_type_prefix (sub, v);
  324.     /* A tree for a member pointer looks like pointer to offset,
  325.        so let the OFFSET_TYPE case handle it.  */
  326.     if (TREE_CODE (sub) != OFFSET_TYPE)
  327.       {
  328.         switch (TREE_CODE (sub))
  329.           {
  330.         /* We don't want int ( *)() */
  331.           case FUNCTION_TYPE:
  332.           case METHOD_TYPE:
  333.         break;
  334.         
  335.           case ARRAY_TYPE:
  336.         OB_PUTC2 (' ', '(');
  337.         break;
  338.  
  339.           case POINTER_TYPE:
  340.         /* We don't want "char * *" */
  341.         if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub)))
  342.           break;
  343.         /* But we do want "char *const *" */
  344.         
  345.           default:
  346.         OB_PUTC (' ');
  347.           }
  348.         OB_PUTC ('*');
  349.         dump_readonly_or_volatile (t, none);
  350.       }
  351.       }
  352.       break;
  353.  
  354.     case REFERENCE_TYPE:
  355.       {
  356.     tree sub = TREE_TYPE (t);
  357.     dump_type_prefix (sub, v);
  358.  
  359.     switch (TREE_CODE (sub))
  360.       {
  361.       case ARRAY_TYPE:
  362.         OB_PUTC2 (' ', '(');
  363.         break;
  364.  
  365.       case POINTER_TYPE:
  366.         /* We don't want "char * &" */
  367.         if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub)))
  368.           break;
  369.         /* But we do want "char *const &" */
  370.  
  371.       default:
  372.         OB_PUTC (' ');
  373.       }
  374.       }
  375.       OB_PUTC ('&');
  376.       dump_readonly_or_volatile (t, none);
  377.       break;
  378.  
  379.     case OFFSET_TYPE:
  380.     offset_type:
  381.       dump_type_prefix (TREE_TYPE (t), v);
  382.       if (TREE_CODE (t) == OFFSET_TYPE)    /* pmfs deal with this in d_t_p */
  383.     {
  384.       OB_PUTC (' ');
  385.       dump_type (TYPE_OFFSET_BASETYPE (t), 0);
  386.       OB_PUTC2 (':', ':');
  387.     }
  388.       OB_PUTC ('*');
  389.       dump_readonly_or_volatile (t, none);
  390.       break;
  391.  
  392.       /* Can only be reached through function pointer -- this would not be
  393.          correct if FUNCTION_DECLs used it.  */
  394.     case FUNCTION_TYPE:
  395.       dump_type_prefix (TREE_TYPE (t), v);
  396.       OB_PUTC2 (' ', '(');
  397.       break;
  398.  
  399.     case METHOD_TYPE:
  400.       dump_type_prefix (TREE_TYPE (t), v);
  401.       OB_PUTC2 (' ', '(');
  402.       dump_aggr_type (TYPE_METHOD_BASETYPE (t), 0);
  403.       OB_PUTC2 (':', ':');
  404.       break;
  405.  
  406.     case ARRAY_TYPE:
  407.       dump_type_prefix (TREE_TYPE (t), v);
  408.       break;
  409.  
  410.     case ENUMERAL_TYPE:
  411.     case ERROR_MARK:
  412.     case IDENTIFIER_NODE:
  413.     case INTEGER_TYPE:
  414.     case BOOLEAN_TYPE:
  415.     case REAL_TYPE:
  416.     case RECORD_TYPE:
  417.     case TEMPLATE_TYPE_PARM:
  418.     case TREE_LIST:
  419.     case TYPE_DECL:
  420.     case TREE_VEC:
  421.     case UNINSTANTIATED_P_TYPE:
  422.     case UNION_TYPE:
  423.     case UNKNOWN_TYPE:
  424.     case VOID_TYPE:
  425.       dump_type (t, v);
  426.       break;
  427.       
  428.     default:
  429.       sorry ("`%s' not supported by dump_type_prefix",
  430.          tree_code_name[(int) TREE_CODE (t)]);
  431.     }
  432. }
  433.  
  434. static void
  435. dump_type_suffix (t, v)
  436.      tree t;
  437.      int v;            /* verbose? */
  438. {
  439.   if (TYPE_PTRMEMFUNC_P (t))
  440.     t = TYPE_PTRMEMFUNC_FN_TYPE (t);
  441.  
  442.   switch (TREE_CODE (t))
  443.     {
  444.     case POINTER_TYPE:
  445.     case REFERENCE_TYPE:
  446.     case OFFSET_TYPE:
  447.       if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
  448.     OB_PUTC (')');
  449.       dump_type_suffix (TREE_TYPE (t), v);
  450.       break;
  451.  
  452.       /* Can only be reached through function pointer */
  453.     case FUNCTION_TYPE:
  454.     case METHOD_TYPE:
  455.       {
  456.     tree arg;
  457.     OB_PUTC2 (')', '(');
  458.     arg = TYPE_ARG_TYPES (t);
  459.     if (TREE_CODE (t) == METHOD_TYPE)
  460.       arg = TREE_CHAIN (arg);
  461.  
  462.     if (arg)
  463.       dump_type (arg, v);
  464.     else
  465.       OB_PUTS ("...");
  466.     OB_PUTC (')');
  467.     if (TREE_CODE (t) == METHOD_TYPE)
  468.       dump_readonly_or_volatile
  469.         (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
  470.     dump_type_suffix (TREE_TYPE (t), v);
  471.     break;
  472.       }
  473.  
  474.     case ARRAY_TYPE:
  475.       OB_PUTC ('[');
  476.       if (TYPE_DOMAIN (t))
  477.     OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) + 1);
  478.       OB_PUTC (']');
  479.       dump_type_suffix (TREE_TYPE (t), v);
  480.       break;
  481.       
  482.     case ENUMERAL_TYPE:
  483.     case ERROR_MARK:
  484.     case IDENTIFIER_NODE:
  485.     case INTEGER_TYPE:
  486.     case BOOLEAN_TYPE:
  487.     case REAL_TYPE:
  488.     case RECORD_TYPE:
  489.     case TEMPLATE_TYPE_PARM:
  490.     case TREE_LIST:
  491.     case TYPE_DECL:
  492.     case TREE_VEC:
  493.     case UNINSTANTIATED_P_TYPE:
  494.     case UNION_TYPE:
  495.     case UNKNOWN_TYPE:
  496.     case VOID_TYPE:
  497.       break;
  498.  
  499.     default:
  500.       sorry ("`%s' not supported by dump_type_suffix",
  501.          tree_code_name[(int) TREE_CODE (t)]);
  502.     }
  503. }
  504.  
  505. /* Return a function declaration which corresponds to the IDENTIFIER_NODE
  506.    argument.  */
  507. tree
  508. ident_fndecl (t)
  509.      tree t;
  510. {
  511.   tree n = lookup_name (t, 0);
  512.  
  513.   if (TREE_CODE (n) == FUNCTION_DECL)
  514.     return n;
  515.   else if (TREE_CODE (n) == TREE_LIST
  516.        && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL)
  517.     return TREE_VALUE (n);
  518.  
  519.   my_friendly_abort (66);
  520.   return NULL_TREE;
  521. }
  522.  
  523. #ifndef NO_DOLLAR_IN_LABEL
  524. #  define GLOBAL_THING "_GLOBAL_$"
  525. #else
  526. #  ifndef NO_DOT_IN_LABEL
  527. #    define GLOBAL_THING "_GLOBAL_."
  528. #  else
  529. #    define GLOBAL_THING "_GLOBAL__"
  530. #  endif
  531. #endif
  532.  
  533. #define GLOBAL_IORD_P(NODE) \
  534.   !strncmp(IDENTIFIER_POINTER(NODE),GLOBAL_THING,sizeof(GLOBAL_THING)-1)
  535.  
  536. void
  537. dump_global_iord (t)
  538.      tree t;
  539. {
  540.   char *name = IDENTIFIER_POINTER (t);
  541.  
  542.   OB_PUTS ("(static ");
  543.   if (name [sizeof (GLOBAL_THING) - 1] == 'I')
  544.     OB_PUTS ("initializers");
  545.   else if (name [sizeof (GLOBAL_THING) - 1] == 'D')
  546.     OB_PUTS ("destructors");
  547.   else
  548.     my_friendly_abort (352);
  549.   
  550.   OB_PUTS (" for ");
  551.   OB_PUTCP (input_filename);
  552.   OB_PUTC (')');
  553. }
  554.  
  555. static void
  556. dump_decl (t, v)
  557.      tree t;
  558.      int v;            /* verbosity */
  559. {
  560.   if (t == NULL_TREE)
  561.     return;
  562.  
  563.   switch (TREE_CODE (t))
  564.     {
  565.     case ERROR_MARK:
  566.       OB_PUTS (" /* decl error */ ");
  567.       break;
  568.  
  569.     case TYPE_DECL:
  570.       {
  571.     /* Don't say 'typedef class A' */
  572.     tree type = TREE_TYPE (t);
  573.         if (((IS_AGGR_TYPE (type) && ! TYPE_PTRMEMFUNC_P (type))
  574.          || TREE_CODE (type) == ENUMERAL_TYPE)
  575.         && type == TYPE_MAIN_VARIANT (type))
  576.       {
  577.         dump_type (type, v);
  578.         break;
  579.       }
  580.       }
  581.       if (v > 0)
  582.     OB_PUTS ("typedef ");
  583.       goto general;
  584.       break;
  585.       
  586.     case VAR_DECL:
  587.       if (VTABLE_NAME_P (DECL_NAME (t)))
  588.     {
  589.       OB_PUTS ("vtable for ");
  590.       dump_type (DECL_CONTEXT (t), v);
  591.       break;
  592.     }
  593.       /* else fall through */
  594.     case FIELD_DECL:
  595.     case PARM_DECL:
  596.     general:
  597.       if (v > 0)
  598.     {
  599.       dump_type_prefix (TREE_TYPE (t), v);
  600.       OB_PUTC (' ');
  601.     }
  602.       /* DECL_CLASS_CONTEXT isn't being set in some cases.  Hmm...  */
  603.       if (DECL_CONTEXT (t)
  604.       && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t))) == 't')
  605.     {
  606.       dump_type (DECL_CONTEXT (t), 0);
  607.       OB_PUTC2 (':', ':');
  608.     }
  609.       if (DECL_NAME (t))
  610.     dump_decl (DECL_NAME (t), v);
  611.       else
  612.     OB_PUTS ("{anon}");
  613.       if (v > 0)
  614.     dump_type_suffix (TREE_TYPE (t), v);
  615.       break;
  616.  
  617.     case ARRAY_REF:
  618.       dump_decl (TREE_OPERAND (t, 0), v);
  619.       OB_PUTC ('[');
  620.       dump_decl (TREE_OPERAND (t, 1), v);
  621.       OB_PUTC (']');
  622.       break;
  623.  
  624.       /* So that we can do dump_decl in dump_aggr_type and have it work for
  625.      both class and function scope.  */
  626.     case RECORD_TYPE:
  627.     case UNION_TYPE:
  628.     case ENUMERAL_TYPE:
  629.       dump_type (t, v);
  630.       break;
  631.  
  632.     case TYPE_EXPR:
  633.       my_friendly_abort (69);
  634.       break;
  635.  
  636.       /* These special cases are duplicated here so that other functions
  637.      can feed identifiers to cp_error and get them demangled properly. */
  638.     case IDENTIFIER_NODE:
  639.       if (DESTRUCTOR_NAME_P (t))
  640.     {
  641.       OB_PUTC ('~');
  642.       dump_decl (DECL_NAME (ident_fndecl (t)), 0);
  643.     }
  644.       else if (IDENTIFIER_TYPENAME_P (t))
  645.     {
  646.       OB_PUTS ("operator ");
  647.       /* Not exactly IDENTIFIER_TYPE_VALUE.  */
  648.       dump_type (TREE_TYPE (t), 0);
  649.       break;
  650.     }
  651.       else if (IDENTIFIER_OPNAME_P (t))
  652.     {
  653.       char *name_string = operator_name_string (t);
  654.       OB_PUTS ("operator ");
  655.       OB_PUTCP (name_string);
  656.     }
  657.       else
  658.     OB_PUTID (t);
  659.       break;
  660.  
  661.     case FUNCTION_DECL:
  662.       if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t)))
  663.     dump_global_iord (DECL_ASSEMBLER_NAME (t));
  664.       else
  665.     dump_function_decl (t, v);
  666.       break;
  667.  
  668.     case TEMPLATE_DECL:
  669.       {
  670.     tree args = DECL_TEMPLATE_PARMS (t);
  671.     int i, len = args ? TREE_VEC_LENGTH (args) : 0;
  672.     OB_PUTS ("template <");
  673.     for (i = 0; i < len; i++)
  674.       {
  675.         tree arg = TREE_VEC_ELT (args, i);
  676.         tree defval = TREE_PURPOSE (arg);
  677.         arg = TREE_VALUE (arg);
  678.         if (TREE_CODE (arg) == TYPE_DECL)
  679.           {
  680.         OB_PUTS ("class ");
  681.         OB_PUTID (DECL_NAME (arg));
  682.           }
  683.         else
  684.           dump_decl (arg, 1);
  685.  
  686.         if (defval)
  687.           {
  688.         OB_PUTS (" = ");
  689.         dump_decl (defval, 1);
  690.           }
  691.         
  692.         OB_PUTC2 (',', ' ');
  693.       }
  694.     if (len != 0)
  695.       OB_UNPUT (2);
  696.     OB_PUTC2 ('>', ' ');
  697.  
  698.     if (DECL_TEMPLATE_IS_CLASS (t))
  699.       {
  700.         OB_PUTS ("class ");
  701.         OB_PUTID (DECL_NAME (t));
  702.       }
  703.     else switch (NEXT_CODE (t))
  704.       {
  705.       case METHOD_TYPE:
  706.       case FUNCTION_TYPE:
  707.         dump_function_decl (t, v);
  708.         break;
  709.  
  710.       default:
  711.         my_friendly_abort (353);
  712.       }
  713.       }
  714.       break;
  715.  
  716.     case LABEL_DECL:
  717.       OB_PUTID (DECL_NAME (t));
  718.       break;
  719.  
  720.     case CONST_DECL:
  721.       if (NEXT_CODE (t) == ENUMERAL_TYPE)
  722.     goto general;
  723.       else
  724.     dump_expr (DECL_INITIAL (t), 0);
  725.       break;
  726.  
  727.     default:
  728.       sorry ("`%s' not supported by dump_decl",
  729.          tree_code_name[(int) TREE_CODE (t)]);
  730.     }
  731. }
  732.  
  733. /* Pretty printing for announce_function.  T is the declaration of the
  734.    function we are interested in seeing.  V is non-zero if we should print
  735.    the type that this function returns.  */
  736.  
  737. static void
  738. dump_function_decl (t, v)
  739.      tree t;
  740.      int v;
  741. {
  742.   tree name = DECL_ASSEMBLER_NAME (t);
  743.   tree fntype = TREE_TYPE (t);
  744.   tree parmtypes = TYPE_ARG_TYPES (fntype);
  745.   tree cname = NULL_TREE;
  746.  
  747.   /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT.  */
  748.   if (DECL_CONTEXT (t))
  749.     cname = DECL_CLASS_CONTEXT (t);
  750.   /* this is for partially instantiated template methods */
  751.   else if (TREE_CODE (fntype) == METHOD_TYPE)
  752.     cname = TREE_TYPE (TREE_VALUE (parmtypes));
  753.  
  754.   v = (v > 0);
  755.   
  756.   if (v)
  757.     {
  758.       if (DECL_STATIC_FUNCTION_P (t))
  759.     OB_PUTS ("static ");
  760.     
  761.       if (! IDENTIFIER_TYPENAME_P (name)
  762.       && ! DECL_CONSTRUCTOR_P (t)
  763.       && ! DESTRUCTOR_NAME_P (name))
  764.     {
  765.       dump_type_prefix (TREE_TYPE (fntype), 1);
  766.       OB_PUTC (' ');
  767.     }
  768.     }
  769.  
  770.   if (cname)
  771.     {
  772.       dump_type (cname, 0);
  773.       OB_PUTC2 (':', ':');
  774.       if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
  775.     parmtypes = TREE_CHAIN (parmtypes);
  776.       if (DECL_CONSTRUCTOR_FOR_VBASE_P (t))
  777.     /* Skip past "in_charge" identifier.  */
  778.     parmtypes = TREE_CHAIN (parmtypes);
  779.     }
  780.  
  781.   if (DESTRUCTOR_NAME_P (name))
  782.     parmtypes = TREE_CHAIN (parmtypes);
  783.   
  784.   dump_function_name (t);
  785.   
  786.   OB_PUTC ('(');
  787.  
  788.   if (parmtypes)
  789.     dump_type (parmtypes, v);
  790.   else
  791.     OB_PUTS ("...");
  792.  
  793.   OB_PUTC (')');
  794.  
  795.   if (v && ! IDENTIFIER_TYPENAME_P (name))
  796.     dump_type_suffix (TREE_TYPE (fntype), 1);
  797.  
  798.   if (TREE_CODE (fntype) == METHOD_TYPE)
  799.     {
  800.       if (IS_SIGNATURE (cname))
  801.     /* We look at the type pointed to by the `optr' field of `this.'  */
  802.     dump_readonly_or_volatile
  803.       (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype))))), before);
  804.       else
  805.     dump_readonly_or_volatile
  806.       (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))), before);
  807.     }
  808. }
  809.  
  810. /* Handle the function name for a FUNCTION_DECL node, grokking operators
  811.    and destructors properly.  */
  812. static void
  813. dump_function_name (t)
  814.      tree t;
  815. {
  816.   tree name = DECL_NAME (t);
  817.  
  818.   /* There ought to be a better way to find out whether or not something is
  819.      a destructor.  */
  820.   if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t)))
  821.     {
  822.       OB_PUTC ('~');
  823.       dump_decl (name, 0);
  824.     }
  825.   else if (IDENTIFIER_TYPENAME_P (name))
  826.     {
  827.       /* This cannot use the hack that the operator's return
  828.      type is stashed off of its name because it may be
  829.      used for error reporting.  In the case of conflicting
  830.      declarations, both will have the same name, yet
  831.      the types will be different, hence the TREE_TYPE field
  832.      of the first name will be clobbered by the second.  */
  833.       OB_PUTS ("operator ");
  834.       dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
  835.     }
  836.   else if (IDENTIFIER_OPNAME_P (name))
  837.     {
  838.       char *name_string = operator_name_string (name);
  839.       OB_PUTS ("operator ");
  840.       OB_PUTCP (name_string);
  841.     }
  842.   else
  843.     dump_decl (name, 0);
  844. }
  845.  
  846. static void
  847. dump_char (c)
  848.      char c;
  849. {
  850.   switch (c)
  851.     {
  852.     case TARGET_NEWLINE:
  853.       OB_PUTS ("\\n");
  854.       break;
  855.     case TARGET_TAB:
  856.       OB_PUTS ("\\t");
  857.       break;
  858.     case TARGET_VT:
  859.       OB_PUTS ("\\v");
  860.       break;
  861.     case TARGET_BS:
  862.       OB_PUTS ("\\b");
  863.       break;
  864.     case TARGET_CR:
  865.       OB_PUTS ("\\r");
  866.       break;
  867.     case TARGET_FF:
  868.       OB_PUTS ("\\f");
  869.       break;
  870.     case TARGET_BELL:
  871.       OB_PUTS ("\\a");
  872.       break;
  873.     case '\\':
  874.       OB_PUTS ("\\\\");
  875.       break;
  876.     case '\'':
  877.       OB_PUTS ("\\'");
  878.       break;
  879.     case '\"':
  880.       OB_PUTS ("\\\"");
  881.       break;
  882.     default:
  883.       if (isprint (c))
  884.     OB_PUTC (c);
  885.       else
  886.     {
  887.       sprintf (digit_buffer, "\\%03o", (int) c);
  888.       OB_PUTCP (digit_buffer);
  889.     }
  890.     }
  891. }
  892.  
  893. /* Print out a list of initializers (subr of dump_expr) */
  894. static void
  895. dump_expr_list (l)
  896.      tree l;
  897. {
  898.   while (l)
  899.     {
  900.       dump_expr (TREE_VALUE (l), 0);
  901.       if (TREE_CHAIN (l))
  902.     OB_PUTC2 (',', ' ');
  903.       l = TREE_CHAIN (l);
  904.     }
  905. }
  906.  
  907. /* Print out an expression */
  908. static void
  909. dump_expr (t, nop)
  910.      tree t;
  911.      int nop;            /* suppress parens */
  912. {
  913.   switch (TREE_CODE (t))
  914.     {
  915.     case VAR_DECL:
  916.     case PARM_DECL:
  917.     case FIELD_DECL:
  918.     case CONST_DECL:
  919.     case FUNCTION_DECL:
  920.       dump_decl (t, -1);
  921.       break;
  922.  
  923.     case INTEGER_CST:
  924.       {
  925.     tree type = TREE_TYPE (t);
  926.     my_friendly_assert (type != 0, 81);
  927.  
  928.     /* If it's an enum, output its tag, rather than its value.  */
  929.     if (TREE_CODE (type) == ENUMERAL_TYPE)
  930.       {
  931.         char *p = enum_name_string (t, type);
  932.         OB_PUTCP (p);
  933.       }
  934.     else if (type == char_type_node
  935.          || type == signed_char_type_node
  936.          || type == unsigned_char_type_node)
  937.       {
  938.         OB_PUTC ('\'');
  939.         dump_char (TREE_INT_CST_LOW (t));
  940.         OB_PUTC ('\'');
  941.       }
  942.     else if (TREE_INT_CST_HIGH (t)
  943.          != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
  944.       {
  945.         tree val = t;
  946.         if (TREE_INT_CST_HIGH (val) < 0)
  947.           {
  948.         OB_PUTC ('-');
  949.         val = build_int_2 (~TREE_INT_CST_LOW (val),
  950.                    -TREE_INT_CST_HIGH (val));
  951.           }
  952.         /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
  953.            systems?  */
  954.         {
  955.           static char format[10]; /* "%x%09999x\0" */
  956.           if (!format[0])
  957.         sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
  958.           sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
  959.                TREE_INT_CST_LOW (val));
  960.           OB_PUTCP (digit_buffer);
  961.         }
  962.       }
  963.     else
  964.       OB_PUTI (TREE_INT_CST_LOW (t));
  965.       }
  966.       break;
  967.  
  968.     case REAL_CST:
  969. #ifndef REAL_IS_NOT_DOUBLE
  970.       sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
  971. #else
  972.       {
  973.     unsigned char *p = (unsigned char *) &TREE_REAL_CST (t);
  974.     int i;
  975.     strcpy (digit_buffer, "0x");
  976.     for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
  977.       sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
  978.       }
  979. #endif
  980.       OB_PUTCP (digit_buffer);
  981.       break;
  982.  
  983.     case STRING_CST:
  984.       {
  985.     char *p = TREE_STRING_POINTER (t);
  986.     int len = TREE_STRING_LENGTH (t) - 1;
  987.     int i;
  988.  
  989.     OB_PUTC ('\"');
  990.     for (i = 0; i < len; i++)
  991.       dump_char (p[i]);
  992.     OB_PUTC ('\"');
  993.       }
  994.       break;
  995.  
  996.     case COMPOUND_EXPR:
  997.       dump_binary_op (",", t);
  998.       break;
  999.  
  1000.     case COND_EXPR:
  1001.       OB_PUTC ('(');
  1002.       dump_expr (TREE_OPERAND (t, 0), 0);
  1003.       OB_PUTS (" ? ");
  1004.       dump_expr (TREE_OPERAND (t, 1), 0);
  1005.       OB_PUTS (" : ");
  1006.       dump_expr (TREE_OPERAND (t, 2), 0);
  1007.       OB_PUTC (')');
  1008.       break;
  1009.  
  1010.     case SAVE_EXPR:
  1011.       if (TREE_HAS_CONSTRUCTOR (t))
  1012.     {
  1013.       OB_PUTS ("new ");
  1014.       dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
  1015.       PARM_DECL_EXPR (t) = 1;
  1016.     }
  1017.       else
  1018.     {
  1019.       sorry ("operand of SAVE_EXPR not understood");
  1020.       goto error;
  1021.     }
  1022.       break;
  1023.  
  1024.     case NEW_EXPR:
  1025.       OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
  1026.       OB_PUTC ('(');
  1027.       dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
  1028.       OB_PUTC (')');
  1029.       break;
  1030.  
  1031.     case CALL_EXPR:
  1032.       {
  1033.     tree fn = TREE_OPERAND (t, 0);
  1034.     tree args = TREE_OPERAND (t, 1);
  1035.     
  1036.     if (TREE_CODE (fn) == ADDR_EXPR)
  1037.       fn = TREE_OPERAND (fn, 0);
  1038.  
  1039.     if (NEXT_CODE (fn) == METHOD_TYPE)
  1040.       {
  1041.         tree ob = TREE_VALUE (args);
  1042.         if (TREE_CODE (ob) == ADDR_EXPR)
  1043.           {
  1044.         dump_expr (TREE_OPERAND (ob, 0), 0);
  1045.         OB_PUTC ('.');
  1046.           }
  1047.         else if (TREE_CODE (ob) != PARM_DECL
  1048.              || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
  1049.           {
  1050.         dump_expr (ob, 0);
  1051.         OB_PUTC2 ('-', '>');
  1052.           }
  1053.         args = TREE_CHAIN (args);
  1054.       }
  1055.     dump_expr (fn, 0);
  1056.     OB_PUTC('(');
  1057.     dump_expr_list (args);
  1058.     OB_PUTC (')');
  1059.       }
  1060.       break;
  1061.  
  1062.     case WITH_CLEANUP_EXPR:
  1063.       /* Note that this only works for G++ cleanups.  If somebody
  1064.      builds a general cleanup, there's no way to represent it.  */
  1065.       dump_expr (TREE_OPERAND (t, 0), 0);
  1066.       break;
  1067.  
  1068.     case TARGET_EXPR:
  1069.       /* Note that this only works for G++ target exprs.  If somebody
  1070.      builds a general TARGET_EXPR, there's no way to represent that
  1071.      it initializes anything other that the parameter slot for the
  1072.      default argument.  Note we may have cleared out the first
  1073.      operand in expand_expr, so don't go killing ourselves.  */
  1074.       if (TREE_OPERAND (t, 1))
  1075.     dump_expr (TREE_OPERAND (t, 1), 0);
  1076.       break;
  1077.  
  1078.     case MODIFY_EXPR:
  1079.     case PLUS_EXPR:
  1080.     case MINUS_EXPR:
  1081.     case MULT_EXPR:
  1082.     case TRUNC_DIV_EXPR:
  1083.     case TRUNC_MOD_EXPR:
  1084.     case MIN_EXPR:
  1085.     case MAX_EXPR:
  1086.     case LSHIFT_EXPR:
  1087.     case RSHIFT_EXPR:
  1088.     case BIT_IOR_EXPR:
  1089.     case BIT_XOR_EXPR:
  1090.     case BIT_AND_EXPR:
  1091.     case BIT_ANDTC_EXPR:
  1092.     case TRUTH_ANDIF_EXPR:
  1093.     case TRUTH_ORIF_EXPR:
  1094.     case LT_EXPR:
  1095.     case LE_EXPR:
  1096.     case GT_EXPR:
  1097.     case GE_EXPR:
  1098.     case EQ_EXPR:
  1099.     case NE_EXPR:
  1100.       dump_binary_op (opname_tab[(int) TREE_CODE (t)], t);
  1101.       break;
  1102.  
  1103.     case CEIL_DIV_EXPR:
  1104.     case FLOOR_DIV_EXPR:
  1105.     case ROUND_DIV_EXPR:
  1106.       dump_binary_op ("/", t);
  1107.       break;
  1108.  
  1109.     case CEIL_MOD_EXPR:
  1110.     case FLOOR_MOD_EXPR:
  1111.     case ROUND_MOD_EXPR:
  1112.       dump_binary_op ("%", t);
  1113.       break;
  1114.  
  1115.     case COMPONENT_REF:
  1116.       {
  1117.     tree ob = TREE_OPERAND (t, 0);
  1118.     if (TREE_CODE (ob) == INDIRECT_REF)
  1119.       {
  1120.         ob = TREE_OPERAND (ob, 0);
  1121.         if (TREE_CODE (ob) != PARM_DECL
  1122.         || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
  1123.           {
  1124.         dump_expr (ob, 0);
  1125.         OB_PUTC2 ('-', '>');
  1126.           }
  1127.       }
  1128.     else
  1129.       {
  1130.         dump_expr (ob, 0);
  1131.         OB_PUTC ('.');
  1132.       }
  1133.     dump_expr (TREE_OPERAND (t, 1), 1);
  1134.       }
  1135.       break;
  1136.  
  1137.     case CONVERT_EXPR:
  1138.       dump_unary_op ("+", t, nop);
  1139.       break;
  1140.  
  1141.     case ADDR_EXPR:
  1142.       if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
  1143.       || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)
  1144.     dump_expr (TREE_OPERAND (t, 0), 0);
  1145.       else
  1146.     dump_unary_op ("&", t, nop);
  1147.       break;
  1148.  
  1149.     case INDIRECT_REF:
  1150.       if (TREE_HAS_CONSTRUCTOR (t))
  1151.     {
  1152.       t = TREE_OPERAND (t, 0);
  1153.       my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
  1154.       dump_expr (TREE_OPERAND (t, 0), 0);
  1155.       OB_PUTC ('(');
  1156.       dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
  1157.       OB_PUTC (')');
  1158.     }
  1159.       else
  1160.     {
  1161.       if (NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
  1162.         dump_expr (TREE_OPERAND (t, 0), nop);
  1163.       else
  1164.         dump_unary_op ("*", t, nop);
  1165.     }
  1166.       break;
  1167.  
  1168.     case NEGATE_EXPR:
  1169.     case BIT_NOT_EXPR:
  1170.     case TRUTH_NOT_EXPR:
  1171.     case PREDECREMENT_EXPR:
  1172.     case PREINCREMENT_EXPR:
  1173.       dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, nop);
  1174.       break;
  1175.  
  1176.     case POSTDECREMENT_EXPR:
  1177.     case POSTINCREMENT_EXPR:
  1178.       OB_PUTC ('(');
  1179.       dump_expr (TREE_OPERAND (t, 0), 0);
  1180.       OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
  1181.       OB_PUTC (')');
  1182.       break;
  1183.  
  1184.     case NON_LVALUE_EXPR:
  1185.       /* FIXME: This is a KLUDGE workaround for a parsing problem.  There
  1186.      should be another level of INDIRECT_REF so that I don't have to do
  1187.      this.  */
  1188.       if (NEXT_CODE (t) == POINTER_TYPE)
  1189.     {
  1190.       tree next = TREE_TYPE (TREE_TYPE (t));
  1191.  
  1192.       while (TREE_CODE (next) == POINTER_TYPE)
  1193.         next = TREE_TYPE (next);
  1194.       
  1195.       if (TREE_CODE (next) == FUNCTION_TYPE)
  1196.         {
  1197.           if (!nop) OB_PUTC ('(');
  1198.           OB_PUTC ('*');
  1199.           dump_expr (TREE_OPERAND (t, 0), 1);
  1200.           if (!nop) OB_PUTC (')');
  1201.           break;
  1202.         }
  1203.       /* else FALLTHRU */
  1204.     }
  1205.       dump_expr (TREE_OPERAND (t, 0), 0);
  1206.       break;
  1207.  
  1208.     case NOP_EXPR:
  1209.       dump_expr (TREE_OPERAND (t, 0), nop);
  1210.       break;
  1211.  
  1212.     case CONSTRUCTOR:
  1213.       OB_PUTC ('{');
  1214.       dump_expr_list (CONSTRUCTOR_ELTS (t), 0);
  1215.       OB_PUTC ('}');
  1216.       break;
  1217.  
  1218.     case OFFSET_REF:
  1219.       {
  1220.     tree ob = TREE_OPERAND (t, 0);
  1221.     if (TREE_CODE (ob) == NOP_EXPR
  1222.         && TREE_OPERAND (ob, 0) == error_mark_node
  1223.         && TREE_CODE (TREE_OPERAND (t, 1)) == FUNCTION_DECL)
  1224.         /* A::f */
  1225.       dump_expr (TREE_OPERAND (t, 1), 0);
  1226.     else
  1227.       {
  1228.         sorry ("operand of OFFSET_REF not understood");
  1229.         goto error;
  1230.       }
  1231.     break;
  1232.       }
  1233.  
  1234.     case TREE_LIST:
  1235.       if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
  1236.     {
  1237.       OB_PUTID (DECL_NAME (TREE_VALUE (t)));
  1238.       break;
  1239.     }
  1240.       /* else fall through */    
  1241.  
  1242.       /*  This list is incomplete, but should suffice for now.
  1243.       It is very important that `sorry' does not call
  1244.       `report_error_function'.  That could cause an infinite loop.  */
  1245.     default:
  1246.       sorry ("`%s' not supported by dump_expr",
  1247.          tree_code_name[(int) TREE_CODE (t)]);
  1248.  
  1249.       /* fall through to ERROR_MARK...  */
  1250.     case ERROR_MARK:
  1251.     error:
  1252.       OB_PUTCP ("{error}");
  1253.       break;
  1254.     }
  1255. }
  1256.  
  1257. static void
  1258. dump_binary_op (opstring, t)
  1259.      char *opstring;
  1260.      tree t;
  1261. {
  1262.   OB_PUTC ('(');
  1263.   dump_expr (TREE_OPERAND (t, 0), 1);
  1264.   OB_PUTC (' ');
  1265.   OB_PUTCP (opstring);
  1266.   OB_PUTC (' ');
  1267.   dump_expr (TREE_OPERAND (t, 1), 1);
  1268.   OB_PUTC (')');
  1269. }
  1270.  
  1271. static void
  1272. dump_unary_op (opstring, t, nop)
  1273.      char *opstring;
  1274.      tree t;
  1275.      int nop;
  1276. {
  1277.   if (!nop) OB_PUTC ('(');
  1278.   OB_PUTCP (opstring);
  1279.   dump_expr (TREE_OPERAND (t, 0), 1);
  1280.   if (!nop) OB_PUTC (')');
  1281. }
  1282.  
  1283. char *
  1284. fndecl_as_string (cname, fndecl, print_ret_type_p)
  1285.      tree cname, fndecl;
  1286.      int print_ret_type_p;
  1287. {
  1288.   return decl_as_string (fndecl, print_ret_type_p);
  1289. }
  1290.  
  1291. /* Same, but handtype a _TYPE.
  1292.    Called from convert_to_reference, mangle_class_name_for_template,
  1293.    build_unary_op, and GNU_xref_decl.  */
  1294. char *
  1295. type_as_string (typ, v)
  1296.      tree typ;
  1297.      int v;
  1298. {
  1299.   OB_INIT ();
  1300.  
  1301.   dump_type (typ, v);
  1302.  
  1303.   OB_FINISH ();
  1304.  
  1305.   return (char *)obstack_base (&scratch_obstack);
  1306. }
  1307.  
  1308. char *
  1309. expr_as_string (decl, v)
  1310.      tree decl;
  1311.      int v;
  1312. {
  1313.   OB_INIT ();
  1314.  
  1315.   dump_expr (decl, 1);
  1316.  
  1317.   OB_FINISH ();
  1318.  
  1319.   return (char *)obstack_base (&scratch_obstack);
  1320. }
  1321.  
  1322. /* A cross between type_as_string and fndecl_as_string.
  1323.    Only called from substitute_nice_name.  */
  1324. char *
  1325. decl_as_string (decl, v)
  1326.      tree decl;
  1327.      int v;
  1328. {
  1329.   OB_INIT ();
  1330.  
  1331.   dump_decl (decl, v);
  1332.  
  1333.   OB_FINISH ();
  1334.  
  1335.   return (char *)obstack_base (&scratch_obstack);
  1336. }
  1337.  
  1338. char *
  1339. cp_file_of (t)
  1340.      tree t;
  1341. {
  1342.   if (TREE_CODE (t) == PARM_DECL)
  1343.     return DECL_SOURCE_FILE (DECL_CONTEXT (t));
  1344.   else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
  1345.     return DECL_SOURCE_FILE (TYPE_NAME (t));
  1346.   else
  1347.     return DECL_SOURCE_FILE (t);
  1348. }
  1349.  
  1350. int
  1351. cp_line_of (t)
  1352.      tree t;
  1353. {
  1354.   int line = 0;
  1355.   if (TREE_CODE (t) == PARM_DECL)
  1356.     line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
  1357.   if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t))
  1358.     t = TREE_TYPE (t);
  1359.  
  1360.   if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
  1361.     {
  1362.       if (IS_AGGR_TYPE (t))
  1363.     line = CLASSTYPE_SOURCE_LINE (t);
  1364.       else
  1365.     line = DECL_SOURCE_LINE (TYPE_NAME (t));
  1366.     }
  1367.   else
  1368.     line = DECL_SOURCE_LINE (t);
  1369.  
  1370.   if (line == 0)
  1371.     return lineno;
  1372.  
  1373.   return line;
  1374. }
  1375.  
  1376. char *
  1377. code_as_string (c, v)
  1378.      enum tree_code c;
  1379.      int v;
  1380. {
  1381.   return tree_code_name [c];
  1382. }
  1383.  
  1384. char *
  1385. language_as_string (c, v)
  1386.      enum languages c;
  1387.      int v;
  1388. {
  1389.   switch (c)
  1390.     {
  1391.     case lang_c:
  1392.       return "C";
  1393.  
  1394.     case lang_cplusplus:
  1395.       return "C++";
  1396.  
  1397.     default:
  1398.       my_friendly_abort (355);
  1399.       return 0;
  1400.     }
  1401. }
  1402.  
  1403. /* Return the proper printed version of a parameter to a C++ function.  */
  1404. char *
  1405. parm_as_string (p, v)
  1406.      int p, v;
  1407. {
  1408.   if (p < 0)
  1409.     return "`this'";
  1410.  
  1411.   sprintf (digit_buffer, "%d", p+1);
  1412.   return digit_buffer;
  1413. }
  1414.  
  1415. char *
  1416. op_as_string (p, v)
  1417.      enum tree_code p;
  1418.      int v;
  1419. {
  1420.   static char buf[] = "operator                ";
  1421.  
  1422.   if (p == 0)
  1423.     return "{unknown}";
  1424.   
  1425.   strcpy (buf + 9, opname_tab [p]);
  1426.   return buf;
  1427. }
  1428.  
  1429. char *
  1430. args_as_string (p, v)
  1431.      tree p;
  1432.      int v;
  1433. {
  1434.   if (p == NULL_TREE)
  1435.     return "...";
  1436.  
  1437.   return type_as_string (p, v);
  1438. }
  1439.